package com.lupan.mutithred.cp2_CountDownLatch;

import java.util.concurrent.CountDownLatch;

/**
 * 说明：
 *
 * @author lupan
 * @version 2017/4/11 15:55
 */
public class Main {

    public static void main(String[] args) {

        CountDownLatch comingTag = new CountDownLatch(100);
        CountDownLatch waitTag = new CountDownLatch(1);
        CountDownLatch waitRunTag = new CountDownLatch(100);
        CountDownLatch beginTag = new CountDownLatch(1);
        CountDownLatch endTag = new CountDownLatch(100);

        MyThread[] myThreads = new MyThread[100];
        for (int i = 0; i < myThreads.length; i++) {
            myThreads[i] = new MyThread(comingTag,waitTag,waitRunTag,beginTag,endTag);
            myThreads[i].start();
        }


        try {
            System.out.println("裁判等待所有运动员到来。。。");
            comingTag.await();
            System.out.println("裁判看到所有运动员就位，巡视5秒。。。");
            Thread.sleep(5000);
            waitTag.countDown();
            System.out.println("各就各位！");
            waitRunTag.await();
            Thread.sleep(2000);
            System.out.println("跑！指令枪响！");
            beginTag.countDown();
            endTag.await();
            System.out.println("所有运动员到达终点，统计名次。");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
